package com.buba.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.service.DeviceTypeService;
import com.buba.service.EquipmentArchivesService;
import common.R;
import entity.device.DeviceType;
import entity.device.EquipmentArchives;
import entity.sparemanage.dto.EquipmentArchivesDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.buba.service.PlaceForStorageService;
import entity.device.PlaceForStorage;
import entity.device.dto.addEquipmentArchivesDto;
import utils.PageResult;
import java.util.List;

/**
 * <p>
 * 设备档案 前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/equipment-archives")
public class EquipmentArchivesController {

    @Autowired
    private EquipmentArchivesService equipmentArchivesService;

    @Autowired
    private DeviceTypeService deviceTypeService;

    @Autowired
    private PlaceForStorageService placeForStorageService;

    /* *
     * @Author: beisheng
     * @Descriprion: 分页模糊查询设备信息
     * @Date: 2023/5/22 10:50
     * @Return: common.R
     * @Param: [equipmentArchives]
     */

    @PostMapping("/selAllequArch")
    public R selAllequArch(@RequestBody EquipmentArchivesDto equipmentArchives){
        PageResult pageResult = equipmentArchivesService.selAllequArch(equipmentArchives);
        return R.success(pageResult);
    }

    @GetMapping("/getAllDevice")
    public R getAllDevice(){
        List<EquipmentArchives> delete_flag = equipmentArchivesService.list(new QueryWrapper<EquipmentArchives>().eq("delete_flag", 0));
        for (EquipmentArchives equipmentArchives : delete_flag) {
            DeviceType byId = deviceTypeService.getById(equipmentArchives.getDeviceType());
            equipmentArchives.setDeviceTypeName(byId.getTypeName());
        }
        return R.success(delete_flag);
    }


    /***
     * @Author atlong
     * @Description 查询设备存放位置信息
     * @Date 2023/6/14 9:31
     * @Param []
     * @return common.R
     **/
    @GetMapping("selPlaceForStorages")
    public R selPlaceForStorages() {
        List<PlaceForStorage> list = placeForStorageService.selAllStorage();
        return list != null ? R.success(list) : R.error();
    }


    /***
     * @Author atlong
     * @Description 批量删除设备
     * @Date 2023/6/6 15:44
     * @Param [ids]
     * @return common.R
     **/
    @PostMapping("delEquipmentArchives")
    public R delEquipmentArchives(@RequestBody List<Integer> ids) {
        boolean b = equipmentArchivesService.delEquipmentArchives(ids);
        return b ? R.success() : R.error();
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 添加设备档案信息
     * @Date 2023/6/5 21:16
     * @Param [add]
     **/
    @PostMapping("addEquipmentArchives")
    public R addEquipmentArchives(@RequestBody addEquipmentArchivesDto add) {
        equipmentArchivesService.addEquipmentArchives(add);
        return R.success();
    }

    /***
     * @Author atlong
     * @Description 查询设备类型信息
     * @Date 2023/6/14 8:53
     * @Param []
     * @return common.R
     **/
    @GetMapping("selDeviceTypes")
    public R selDeviceType() {
        List<DeviceType> list = deviceTypeService.selDeviceTypes();
        return list != null ? R.success(list) : R.error();
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 分页模糊全查
     * @Date 2023/5/30 19:12
     * @Param [equipmentArchivesDto]
     **/
    @PostMapping("selEquipmentArchives")
    public R selEquipmentArchives(@RequestBody EquipmentArchivesDto equipmentArchivesDto) {
        utils.pageutil.PageResult pageResult = equipmentArchivesService.selEquipmentArchives(equipmentArchivesDto);
        return R.success(pageResult);
    }

}

